package br.ufpb.di.ppgi.negocio.modelo.homologacao.defesa;

import java.io.Serializable;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;

import org.hibernate.validator.NotNull;

import br.ufpb.di.ppgi.negocio.modelo.defesa.Defesa;
import br.ufpb.di.ppgi.negocio.modelo.usuario.Usuario;

@Entity
public class HomologacaoDefesa implements Serializable {
	private static final long serialVersionUID = -4204261026836960102L;

	@EmbeddedId	private HomologacaoDefesaPK pk;
	@NotNull private boolean homologado;
	@NotNull private boolean respondido;
	
	public HomologacaoDefesa() {}
	
	public HomologacaoDefesa(Defesa defesa, Usuario usuario) {
		this.pk = new HomologacaoDefesaPK(defesa, usuario);
		this.homologado = false;
		this.respondido = false;
	}

	public HomologacaoDefesaPK getPk() {
		return pk;
	}
	public void setPk(HomologacaoDefesaPK pk) {
		this.pk = pk;
	}
	public boolean isHomologado() {
		return homologado;
	}
	public void setHomologado(boolean homologado) {
		this.homologado = homologado;
		setRespondido(true);
	}
	
	public boolean isRespondido() {
		return respondido;
	}
	private void setRespondido(boolean respondido) {
		this.respondido = respondido;
	}
	
	@Override
	public int hashCode() {
		int hash = 0;
		hash += pk.hashCode();
		hash += homologado ? 1 : 0;
		return 0;
	}

	@Override
	public boolean equals(Object object) {
		if(!(object instanceof HomologacaoDefesa)) {
			return false;
		}
		HomologacaoDefesa other = (HomologacaoDefesa) object;
		if(this.pk == null || !this.pk.equals(other.pk))
			return false;
		if(this.homologado != other.homologado)
			return false;
		if(this.respondido != other.respondido)
			return false;
		return true;
	}
	
}
